// 面试版
function deepClone (obj) {
  if (typeof obj !== 'object' || obj == null) return obj
  let result
  result instanceof Array ? result = [] : result = {}
  for (let key in obj) {
    if (obj.hasOwnProperty(key)) {
      result[key] = deepClone(obj[key])
    }
  }
  return result
}
let obj = {
  a: 1,
  b: {
    name: 'abc',
    age: 18
  }
}
const p1 = deepClone(obj)
p1.b.name = 'grh'
console.log(p1)
console.log(obj)
// assign
// let obj = { name: '小王' }
// let newObj = Object.assign({}, obj)
// newObj.name = '小张'
// ...
// let newObj2 = { ...obj }
// newObj2.name = 'abc'
